////<!--异常进场-->
import api from '../../../fetch/api'
import { clearObject, deepCopyObj } from '../../../assets/js/help.js'

export default {
    data() {
        return {
            bigImgPath: '',
            eventTypeInfo: {
                id: '',
                eventType: '',
            },
            eventTypeInfoRules: {
                eventType: [
                    { required: true, message: '事件类型名称不能为空', trigger: 'change' },
                 
                ],
            },
            eventTypeInfoItems:[],
            picPath:[],
            delNo:'',
        }
    },
    
    computed: {
        showAddIcon() {
          return this.eventTypeInfoItems.length - 1;
        }
    },
    created() {
        // this.getItemList();
        this.getTypeList();
        this.initEventTypeSearch();
    },
    methods: {
        getList() {
            let params = $.extend({}, this.searchParams, this.otherParams);
            console.log(this.otherParams)
            this.getItemList(params);
        },
        showBigImgModal(name, path) {
            this.bigImgPath = path;
            this.toOpenImgModal(name, path);
        },
        showPicModal(name, path) {
            this.picPath = path;
            this.toOpenImgModal(name, path);
        },
        //获取列表
        getItemList(aparams) {
            let self = this,
                params = {
                    page: this.pageNumber,
                    rp: this.pageSize
                };
            params = $.extend({}, params, aparams);
            api.fetchGet('/parkingEvent/list.do', params)
                .then(res => {
                    let data = res.data,
                        list = data.rows;
                    self.tbodysInfo = list;
                    self.total = data.total;
                }, err => { })
        },
        //获取列表
        getTypeList(aparams) {
            let self = this,
                params = {
                };
            var tep=[];
            self.typeInfo=[];
            params = $.extend({}, params, aparams);
            api.fetchGet('/parkingEventType/list.do', params)
                .then(res => {
                    let data = res.data;
                    tep = data;                    
                    var option={
                        name: '',
                        value: null,
                    };                    
                    option['name']='全部';
                    option['value']='';
                    self.typeInfo.push(option);
                    console.log(tep);
                    for(var i=0;i<tep.length;i++){
                        var option1={
                            name: '',
                            value: null,
                        };                        
                        var name=tep[i].eventType;
                        var value=tep[i].id;
                        option1['name']=name;
                        option1['value']=value;
                        self.typeInfo.push(option1);
                    }
                }, err => { });
            
        },
        getTypeListX(aparams) {
            let self = this,
                params = {
                };
            params = $.extend({}, params, aparams);
            api.fetchGet('/parkingEventType/list.do', params)
                .then(res => {
                    let data = res.data;
                    self.eventTypeInfoItems = data;
                }, err => { });            
        },
        initEventTypeSearch(){
            let self = this;            
            self.searchList[3].options=self.typeInfo;
        },
        exportData() {
            let self = this;
            let theadsArr = []
            for(let i = 0; i<self.theadsInfo.length; i++){
            if(self.theadsInfo[i].checked){
                theadsArr.push(self.theadsInfo[i].prop)
            }
            }
            let params = {
                meterList: theadsArr.join(',')
            };
            params = $.extend({}, params, this.searchParams, this.otherParams);
            self.showDialog("确认导出该报表?", '', function () {
                self.toExportAsync('parkingEvent/export.do', params)
            })

        },
        typeModal_open() {
            this.eventTypeInfoItems = [];
            this.eventTypeInfo = {
                id: null,
                eventType: '',
            };
            this.getTypeListX();
            this.toOpenModal('typeModal');
        },
        typeModal_save(formName) {
            var self = this;
            this.$refs[formName].validate((valid) => {
              if (valid) {
                let eventTypeInfo = self.eventTypeInfo;
                if(eventTypeInfo.eventType==null || eventTypeInfo.eventType==''){
                    self.toOpenModal('voidTipModal');
                    return;
                }
                for(var i=0;i<self.eventTypeInfoItems.length;i++){
                    if(self.eventTypeInfoItems[i].eventType==eventTypeInfo.eventType){
                        self.toOpenModal('repeatTipModal');
                        return;
                    }
                }
                self.eventTypeInfoItems.push(eventTypeInfo);
                self.eventTypeInfo = {
                    id: null,
                    eventType: '',
                };
              } else {
                return false;
              }
            });
            
        },
        typeModal_del_open(index) {
            this.delNo=index;
            this.toOpenModal('delConfirmTipModal');
        },
        typeModal_del(index) {
            var self=this;
            if(self.eventTypeInfoItems[index].id!=null){
                var params = {parkingEventTypeId : self.eventTypeInfoItems[index].id};
                self.eventTypeInfoItems.splice(index, 1);
                api.fetchPost('/parkingEventType/del.do', params)
                .then(res => {
                    //start
                    if (res.status == 1) {
                        self.showToast(res.message, 1, 2000);
                        //初始化搜索列表
                        this.getTypeList();
                        this.initEventTypeSearch();
                        self.closed('delConfirmTipModal', 1);
                        return;
                    } else {
                        self.showToast(res.message, 2, 2000)
                        return;
                    }
                    //end
                }, err => { });
            }else{
                self.eventTypeInfoItems.splice(index, 1);
                self.closed('delConfirmTipModal', 1);
            }           
           
        },        
        submitTypeForm() {
            var self = this;
            let tempNo=0;
            if(0==self.eventTypeInfoItems.length){
                self.showToast('事件类型不能为空，请重新设置', 2, 2000);
                return;
            }
            for(let i=0;i<self.eventTypeInfoItems.length;i++){
                if(self.eventTypeInfoItems[i].id!=null){
                    tempNo++;
                }
            }
            if(tempNo==self.eventTypeInfoItems.length){
                self.showToast('没有改变现有事件类型，请重新设置', 2, 2000);
                return;
            }
            //获取表单对象
            var params = {eventTypeInfoItems: JSON.stringify(self.eventTypeInfoItems)};
            api.fetchPost('/parkingEventType/save.do', params)
            .then(res => {
                //start
                if (res.status == 1) {
                    self.showToast(res.message, 1, 2000);
                    self.closed('typeModal', 1);
                     //初始化搜索列表
                    this.getTypeList();
                    this.initEventTypeSearch();
                } else {
                    self.showToast(res.message, 2, 2000);
                    return;
                }
                //end
            }, err => { });
           
        },
    }
}